package pl.edu.mimuw.irs.core.model.design;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import pl.edu.mimuw.irs.core.global.IDManager;
import pl.edu.mimuw.irs.core.model.design.Fragmentation.Type;
import pl.edu.mimuw.irs.core.model.design.processing.Requirement;
import pl.edu.mimuw.irs.core.util.Position;

/**
 * @author Jakub Rauch
 * Created on: 2009-05-07
 */
public class IRSRequirement extends IRSPlace {
	
	private static final long serialVersionUID = 3997013035980030550L;
	
	// *** Attributes
	private List<Requirement> requirements;
	private Map<Requirement, Integer> requirementsMap; 
	// Node supports
	private final static Set<Fragmentation.Type> supportedFragmentations;
	static {
		supportedFragmentations = new LinkedHashSet<Type>();
		supportedFragmentations.add(Type.NONE);
	}
	public List<Requirement> getRequirements() {
		if (requirements == null) requirements = new ArrayList<Requirement>();
		return requirements;
	}
	public Map<Requirement, Integer> getRequirementsMap() {
		/*
		 * TODO : should be cached somehow (could be done by overriding array
		 * and setting dirty flag to this requirement).
		 */
		requirementsMap = new LinkedHashMap<Requirement, Integer>();
		for (Requirement requirement : getRequirements()) {
			Integer value = requirementsMap.get(requirement);
			if (value == null) {
				requirementsMap.put(requirement, new Integer(1));
			} else {
				requirementsMap.put(requirement, value + 1);
			}
		}
		return requirementsMap;
	}
	public void setRequirements(List<Requirement> requirements) {
		this.requirements = requirements;
	}
	@Override
	public Set<Type> getSupportedFragmentations() {
		return supportedFragmentations;
	}
	
	// *** Constructors

	public IRSRequirement(IDManager idManager, String id, NodeType nodeType, Position position, int tokens) {
		super(idManager, id, nodeType, position, tokens);
	}
	
	public IRSRequirement(IDManager idManager, String id, Position position, int tokens) {
		super(idManager, id, position, tokens);
	}

	public IRSRequirement(IDManager idManager, Position position) {
		super(idManager, position);
	}

	public IRSRequirement(IDManager idManager) {
		super(idManager);
	}
	
	// *** Methods
}
